package com.dream.vo.order;

import java.io.Serializable;

import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.constraints.NotBlank;

import com.dream.model.order.OnlineOrder;
import com.dream.model.order.OnlineOrder.OrderStatus;
import com.dream.utils.date.DateParseUtils;
import com.dream.vo.base.FirstGroup;
import com.dream.vo.base.SecondGroup;

public class OrderVO implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1589637623797728803L;
	
	private Long id;
	
	private Long productId;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String orderType;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String urgentLevel;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String mandatoryLevel;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String orderDate;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String orderTime;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String orderUser;
	
	@NotBlank(message = "err0001",groups = {FirstGroup.class})
	private String orderMobile;
	
	private Long hitchType;
	
	private String hitchComments;
	
	private String comments;
	
	private OrderStatus status;
	
	
	/* repair line*/
	private String repairCost;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String serviceType;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String serviceCost;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String distance;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String travelCost;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String visitCost;
	
	private String otherCost;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String satisfaction;
	
	private String partCost;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String repairType;
	
	@NotBlank(message = "err0001",groups = {SecondGroup.class})
	private String repairDate;
	
	private String repairComments;
	
	public OrderStatus getStatus() {
		return status;
	}

	public void setStatus(OrderStatus status) {
		this.status = status;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getProductId() {
		return productId;
	}

	public void setProductId(Long productId) {
		this.productId = productId;
	}

	public Long getHitchType() {
		return hitchType;
	}

	public void setHitchType(Long hitchType) {
		this.hitchType = hitchType;
	}

	public String getOrderType() {
		return orderType;
	}

	public void setOrderType(String orderType) {
		this.orderType = orderType;
	}

	public String getUrgentLevel() {
		return urgentLevel;
	}

	public void setUrgentLevel(String urgentLevel) {
		this.urgentLevel = urgentLevel;
	}

	public String getMandatoryLevel() {
		return mandatoryLevel;
	}

	public void setMandatoryLevel(String mandatoryLevel) {
		this.mandatoryLevel = mandatoryLevel;
	}

	public String getOrderDate() {
		return orderDate;
	}

	public void setOrderDate(String orderDate) {
		this.orderDate = orderDate;
	}

	public String getOrderTime() {
		return orderTime;
	}

	public void setOrderTime(String orderTime) {
		this.orderTime = orderTime;
	}

	public String getOrderUser() {
		return orderUser;
	}

	public void setOrderUser(String orderUser) {
		this.orderUser = orderUser;
	}

	public String getOrderMobile() {
		return orderMobile;
	}

	public void setOrderMobile(String orderMobile) {
		this.orderMobile = orderMobile;
	}

	public String getHitchComments() {
		return hitchComments;
	}

	public void setHitchComments(String hitchComments) {
		this.hitchComments = hitchComments;
	}

	public String getComments() {
		return comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}
	
	
	public String getRepairCost() {
		return repairCost;
	}

	public void setRepairCost(String repairCost) {
		this.repairCost = repairCost;
	}

	public String getServiceType() {
		return serviceType;
	}

	public void setServiceType(String serviceType) {
		this.serviceType = serviceType;
	}

	public String getServiceCost() {
		return serviceCost;
	}

	public void setServiceCost(String serviceCost) {
		this.serviceCost = serviceCost;
	}

	public String getDistance() {
		return distance;
	}

	public void setDistance(String distance) {
		this.distance = distance;
	}

	public String getTravelCost() {
		return travelCost;
	}

	public void setTravelCost(String travelCost) {
		this.travelCost = travelCost;
	}

	public String getVisitCost() {
		return visitCost;
	}

	public void setVisitCost(String visitCost) {
		this.visitCost = visitCost;
	}

	public String getOtherCost() {
		return otherCost;
	}

	public void setOtherCost(String otherCost) {
		this.otherCost = otherCost;
	}

	public String getSatisfaction() {
		return satisfaction;
	}

	public void setSatisfaction(String satisfaction) {
		this.satisfaction = satisfaction;
	}

	public String getPartCost() {
		return partCost;
	}

	public void setPartCost(String partCost) {
		this.partCost = partCost;
	}

	public String getRepairType() {
		return repairType;
	}

	public void setRepairType(String repairType) {
		this.repairType = repairType;
	}

	public String getRepairDate() {
		return repairDate;
	}

	public void setRepairDate(String repairDate) {
		this.repairDate = repairDate;
	}

	public String getRepairComments() {
		return repairComments;
	}

	public void setRepairComments(String repairComments) {
		this.repairComments = repairComments;
	}

	public void populate(OnlineOrder order){
		
		if(order == null){return;}
		
		if(id == null){
		
			order.setUrgentLevel(parseLong(urgentLevel));
			order.setOrderMobile(orderMobile);
			order.setOrderUser(orderUser);
			order.setOrderDate(DateParseUtils.parseDateWithNull(String.format("%s %s", orderDate,orderTime)));
			
			order.setHitchComments(hitchComments);
			order.setHitchType(hitchType);
			order.setComments(comments);
			
			order.setType(parseLong(orderType));
			
		}
		
		order.setStatus(status);
		order.setProductId(productId);
		order.setMandatoryLevel(parseLong(mandatoryLevel));
		order.setRepairCost(parseFloat(repairCost));
		order.setServiceType(this.parseLong(serviceType));
		
		order.setServiceCost(this.parseFloat(serviceCost));
		order.setDistance(this.parseLong(distance));
		
		order.setTravelCost(this.parseFloat(travelCost));
		order.setVisitCost(this.parseFloat(visitCost));
		
		order.setOtherCost(this.parseFloat(otherCost));
		order.setSatisfaction(this.parseLong(this.satisfaction));
		
		order.setPartCost(parseFloat(partCost));
		order.setRepairType(this.parseLong(repairType));
		
		order.setRepairComments(repairComments);
		order.setRepairDate(DateParseUtils.parseDateWithNull(repairDate));
		
	}
	
	private Long parseLong(String val){
		if(StringUtils.isBlank(val)) return null;
		return Long.parseLong(val);
	}
	
	private Float parseFloat(String val){
		if(StringUtils.isBlank(val)) return null;
		return Float.parseFloat(val);
	}
	
}
